home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / kernel / sys / sysStubs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-19  |  10.1 KB  |  521 lines

  1. /* 
  2.  * sysStubs.c --
  3.  *
  4.  *    Stubs for Unix compatible system calls.
  5.  *
  6.  * Copyright 1990 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /cdrom/src/kernel/Cvsroot/kernel/sys/sysStubs.c,v 1.5 92/06/15 22:29:26 jhh Exp $";
  18. #endif /* not lint */
  19.  
  20. #define MACH_UNIX_COMPAT
  21.  
  22. #include <sprite.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <status.h>
  26. #include <errno.h>
  27. #include <user/sys/types.h>
  28. #include <user/sys/wait.h>
  29. #include <user/sys/time.h>
  30. #include <user/sys/resource.h>
  31. #include <mach.h>
  32. #include <proc.h>
  33. #include <vm.h>
  34. #include <fsutil.h>
  35. #include <assert.h>
  36.  
  37. int debugSysStubs;
  38.  
  39.  
  40. /*
  41.  *----------------------------------------------------------------------
  42.  *
  43.  * Sys_NopStub --
  44.  *
  45.  *      This routine performs a nop.  It is for system calls that
  46.  *    need to exist, but don't need any functionality.
  47.  *
  48.  * Results:
  49.  *      Returns 0.
  50.  *
  51.  * Side effects:
  52.  *      None.
  53.  *
  54.  *
  55.  *----------------------------------------------------------------------
  56.  */
  57. int
  58. Sys_NopStub()
  59. {
  60.     return 0;
  61. }
  62.  
  63. /*
  64.  *----------------------------------------------------------------------
  65.  *
  66.  * Sys_RebootStub --
  67.  *
  68.  *      The stub for the "reboot" Unix system call.
  69.  *
  70.  * Results:
  71.  *      None.
  72.  *
  73.  * Side effects:
  74.  *      Any side effects associated with the call.
  75.  *
  76.  *
  77.  *----------------------------------------------------------------------
  78.  */
  79. /*ARGSUSED*/
  80. int
  81. Sys_RebootStub(howto)
  82.     int howto;
  83. {
  84.     printf("reboot is not implemented.\n");
  85.     Mach_SetErrno(EINVAL);
  86.     return -1;
  87. }
  88.  
  89. #define MAX_HOST_NAME_LEN 255
  90.  
  91. static char sysDomainName[MAX_HOST_NAME_LEN + 1];
  92. static int sysDomainNameLen = 0;
  93. int sysHostID;
  94.  
  95.  
  96. /*
  97.  *----------------------------------------------------------------------
  98.  *
  99.  * Sys_GethostnameStub --
  100.  *
  101.  *      The stub for the "gethostname" Unix system call.
  102.  *
  103.  * Results:
  104.  *      None.
  105.  *
  106.  * Side effects:
  107.  *      Any side effects associated with the call.
  108.  *
  109.  *
  110.  *----------------------------------------------------------------------
  111.  */
  112. int
  113. Sys_GethostnameStub(name, namelen)
  114.     char *name;
  115.     int namelen;
  116. {
  117.     int copyLen;
  118.     ReturnStatus status;
  119.  
  120.     if (debugSysStubs) {
  121.     printf("Sys_GethostnameStub\n");
  122.     }
  123.     copyLen = strlen(sys_HostName) + 1;
  124.     if (namelen < copyLen) {
  125.     copyLen = namelen;
  126.     }
  127.     status = Vm_CopyOut(copyLen, sys_HostName, name);
  128.     if (status != SUCCESS) {
  129.     Mach_SetErrno(Compat_MapCode(status));
  130.     return -1;
  131.     }
  132.     return 0;
  133. }
  134.  
  135. /*
  136.  * MAXHOSTNAMELEN is defined here because including the correct 
  137.  * header file (sys/param.h) causes lots of problems because it
  138.  * includes signal.h whose definitions conflict with ultrixSignal.h
  139.  */
  140.  
  141. #define MAXHOSTNAMELEN        64
  142.  
  143.  
  144. /*
  145.  *----------------------------------------------------------------------
  146.  *
  147.  * Sys_SethostnameStub --
  148.  *
  149.  *      The stub for the "sethostname" Unix system call.
  150.  *
  151.  * Results:
  152.  *      None.
  153.  *
  154.  * Side effects:
  155.  *      Any side effects associated with the call.
  156.  *
  157.  *
  158.  *----------------------------------------------------------------------
  159.  */
  160. int
  161. Sys_SethostnameStub(name, namelen)
  162.     char *name;
  163.     int namelen;
  164. {
  165.     Proc_ControlBlock    *procPtr = Proc_GetEffectiveProc();
  166.     ReturnStatus    status;
  167.     char        tmp[MAXHOSTNAMELEN];
  168.  
  169.     if (debugSysStubs) {
  170.     printf("Sys_SethostnameStub\n");
  171.     }
  172.     if (procPtr->userID!=0) {
  173.     Mach_SetErrno(EPERM);
  174.     return -1;
  175.     }
  176.     if (namelen > MAXHOSTNAMELEN - 1) {
  177.     Mach_SetErrno(EINVAL);
  178.     return -1;
  179.     }
  180.     status = Vm_CopyIn(namelen, name, tmp);
  181.     if (status != SUCCESS) {
  182.     Mach_SetErrno(Compat_MapCode(status));
  183.     return -1;
  184.     }
  185.     tmp[namelen] = '\0';
  186.     strcpy(sys_HostName, tmp);
  187.     return 0;
  188. }
  189.  
  190.  
  191. /*
  192.  *----------------------------------------------------------------------
  193.  *
  194.  * Sys_GethostidStub --
  195.  *
  196.  *      The stub for the "gethostid" Unix system call.
  197.  *
  198.  * Results:
  199.  *      None.
  200.  *
  201.  * Side effects:
  202.  *      Any side effects associated with the call.
  203.  *
  204.  *
  205.  *----------------------------------------------------------------------
  206.  */
  207. int
  208. Sys_GethostidStub()
  209.  
  210. {
  211.  
  212.     if (debugSysStubs) {
  213.     printf("Sys_GethostidStub\n");
  214.     }
  215.     return sysHostID;
  216. }
  217.  
  218.  
  219. /*
  220.  *----------------------------------------------------------------------
  221.  *
  222.  * Sys_SethostidStub --
  223.  *
  224.  *      The stub for the "sethostid" Unix system call.
  225.  *
  226.  * Results:
  227.  *      None.
  228.  *
  229.  * Side effects:
  230.  *      Any side effects associated with the call.
  231.  *
  232.  *
  233.  *----------------------------------------------------------------------
  234.  */
  235. int
  236. Sys_SethostidStub(hostid)
  237.     int hostid;
  238. {
  239.  
  240.     if (debugSysStubs) {
  241.     printf("Sys_SethostidStub\n");
  242.     }
  243.     sysHostID = hostid;
  244.     return 0;
  245. }
  246.  
  247.  
  248. /*
  249.  *----------------------------------------------------------------------
  250.  *
  251.  * Sys_GetdomainnameStub --
  252.  *
  253.  *      The stub for the "getdomainname" Unix system call.
  254.  *
  255.  * Results:
  256.  *      None.
  257.  *
  258.  * Side effects:
  259.  *      Any side effects associated with the call.
  260.  *
  261.  *
  262.  *----------------------------------------------------------------------
  263.  */
  264. int
  265. Sys_GetdomainnameStub(name, namelen)
  266.     char *name;
  267.     int namelen;
  268. {
  269.     ReturnStatus    status;
  270.     int copyLen;
  271.  
  272.     if (debugSysStubs) {
  273.     printf("Sys_GetdomainnameStub\n");
  274.     }
  275.     if (namelen < sysDomainNameLen + 1) {
  276.     copyLen = namelen;
  277.     } else {
  278.     copyLen = sysDomainNameLen + 1;
  279.     }
  280.     status = Vm_CopyOut(copyLen, sysDomainName, name);
  281.     if (status != SUCCESS) {
  282.     Mach_SetErrno(Compat_MapCode(status));
  283.     return -1;
  284.     }
  285.     return 0;
  286. }
  287.  
  288.  
  289. /*
  290.  *----------------------------------------------------------------------
  291.  *
  292.  * Sys_SetdomainnameStub --
  293.  *
  294.  *      The stub for the "setdomainname" Unix system call.
  295.  *
  296.  * Results:
  297.  *      None.
  298.  *
  299.  * Side effects:
  300.  *      Any side effects associated with the call.
  301.  *
  302.  *
  303.  *----------------------------------------------------------------------
  304.  */
  305. int
  306. Sys_SetdomainnameStub(name, namelen)
  307.     char *name;
  308.     int namelen;
  309. {
  310.     Proc_ControlBlock    *procPtr = Proc_GetEffectiveProc();
  311.     ReturnStatus    status;
  312.  
  313.     if (procPtr->userID!=0) {
  314.     Mach_SetErrno(EPERM);
  315.     return -1;
  316.     }
  317.     if (debugSysStubs) {
  318.     printf("Sys_SetdomainnameStub\n");
  319.     }
  320.     if (namelen > MAX_HOST_NAME_LEN) {
  321.     Mach_SetErrno(EINVAL);
  322.     }
  323.     status = Vm_CopyIn(namelen, name, sysDomainName);
  324.     if (status != SUCCESS) {
  325.     sysDomainNameLen = 0;
  326.     Mach_SetErrno(EFAULT);
  327.     return -1;
  328.     }
  329.     sysDomainName[namelen] = 0;
  330.     sysDomainNameLen = namelen;
  331.     return 0;
  332. }
  333.  
  334.  
  335. /*
  336.  *----------------------------------------------------------------------
  337.  *
  338.  * Sys_ShutdownStub --
  339.  *
  340.  *      The stub for the "shutdown" Unix system call.
  341.  *
  342.  * Results:
  343.  *      None.
  344.  *
  345.  * Side effects:
  346.  *      Any side effects associated with the call.
  347.  *
  348.  *
  349.  *----------------------------------------------------------------------
  350.  */
  351. int
  352. Sys_ShutdownStub()
  353. {
  354.  
  355.     printf("Sys_Shutdown is not implemented\n");
  356.     Mach_SetErrno(EINVAL);
  357.     return -1;
  358. }
  359.  
  360.  
  361. /*
  362.  *----------------------------------------------------------------------
  363.  *
  364.  * Sys_GetpeernameStub --
  365.  *
  366.  *      The stub for the "getpeername" Unix system call.
  367.  *
  368.  * Results:
  369.  *      None.
  370.  *
  371.  * Side effects:
  372.  *      Any side effects associated with the call.
  373.  *
  374.  *
  375.  *----------------------------------------------------------------------
  376.  */
  377. int
  378. Sys_GetpeernameStub()
  379. {
  380.  
  381.     printf("Sys_Getpeername is not implemented\n");
  382.     Mach_SetErrno(EINVAL);
  383.     return -1;
  384. }
  385.  
  386.  
  387. /*
  388.  *----------------------------------------------------------------------
  389.  *
  390.  * Sys_Getrlimit --
  391.  *
  392.  *      The stub for the "getrlimit" Unix system call.
  393.  *    We don't really implement this, so we return INFINITY for
  394.  *    everything except the stack size.  For the stack size, we
  395.  *    return the same as SunOS.
  396.  *
  397.  * Results:
  398.  *      None.
  399.  *
  400.  * Side effects:
  401.  *      Any side effects associated with the call.
  402.  *
  403.  *
  404.  *----------------------------------------------------------------------
  405.  */
  406. #define RLIM_STACK_CUR    0x00200000
  407. #define RLIM_STACK_MAX    0x80000000
  408. int
  409. Sys_GetrlimitStub(resource, rlp)
  410. int resource;
  411. struct rlimit *rlp;
  412. {
  413.  
  414.     struct rlimit rl;
  415.     ReturnStatus status;
  416.  
  417.     if (debugSysStubs) {
  418.     printf("Sys_GethostnameStub(%d, %x)\n", resource, rlp);
  419.     }
  420.     switch (resource) {
  421.     case RLIMIT_CPU:
  422.     case RLIMIT_FSIZE:
  423.     case RLIMIT_DATA:
  424.     case RLIMIT_CORE:
  425.     case RLIMIT_RSS:
  426.         rl.rlim_cur = RLIM_INFINITY;
  427.         rl.rlim_max = RLIM_INFINITY;
  428.     case RLIMIT_STACK:
  429.         rl.rlim_cur = RLIM_STACK_CUR;
  430.         rl.rlim_max = RLIM_STACK_MAX;
  431.         break;
  432.     default:
  433.         Mach_SetErrno(EINVAL);
  434.         return -1;
  435.         break;
  436.     }
  437.     status = Vm_CopyOut(sizeof(struct rlimit), (Address)&rl, (Address)rlp);
  438.     if (status != SUCCESS) {
  439.     Mach_SetErrno(EFAULT);
  440.     return -1;
  441.     }
  442.  
  443.     return 0;
  444. }
  445.  
  446.  
  447. /*
  448.  *----------------------------------------------------------------------
  449.  *
  450.  * Sys_Setrlimit --
  451.  *
  452.  *      The stub for the "setrlimit" Unix system call.
  453.  *
  454.  * Results:
  455.  *      None.
  456.  *
  457.  * Side effects:
  458.  *      Any side effects associated with the call.
  459.  *
  460.  *
  461.  *----------------------------------------------------------------------
  462.  */
  463. int
  464. Sys_SetrlimitStub()
  465. {
  466.  
  467.     printf("Sys_Setrlimit not implemented\n");
  468.     return 0;
  469. }
  470.  
  471.  
  472.  
  473. /*
  474.  *----------------------------------------------------------------------
  475.  *
  476.  * Sys_GetsysinfoStub --
  477.  *
  478.  *      The stub for the "getsysinfo" Unix system call.
  479.  *
  480.  * Results:
  481.  *      None.
  482.  *
  483.  * Side effects:
  484.  *      Any side effects associated with the call.
  485.  *
  486.  *
  487.  *----------------------------------------------------------------------
  488.  */
  489. /*ARGSUSED*/
  490. int
  491. Sys_GetsysinfoStub(op, buffer, nbytes, start, arg)
  492.  
  493.     unsigned  op;
  494.     char      *buffer;
  495.     unsigned   nbytes;
  496.     int       *start;
  497.     char       *arg;
  498. {
  499. #ifdef actually_do_it
  500.     switch (op) {
  501.     case GSI_PROG_ENV:
  502.     case GSI_MAX_UPROCS:
  503.     case GSI_TTYP:
  504.     case GSI_NETBLK:
  505.     case GSI_BOOTDEV:
  506.     case GSI_UACSYS:
  507.     case GSI_UACPARNT:
  508.     case GSI_UACPROC:
  509.     default:
  510.     }
  511. #endif
  512.  
  513.     printf("Sys_getsysinfo not implemented\n");
  514.     /*
  515.      * Just return a 0.  This says that the requested information is
  516.      * not available which is certainly true for the most part.
  517.      */
  518.     return 0;
  519. }
  520.  
  521.